package com.wimcorp.magic.behaviour;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import com.wimcorp.magic.behaviour.attack.DeathTouch;
import com.wimcorp.magic.behaviour.attack.DefaultAttack;
import com.wimcorp.magic.behaviour.attack.DoubleStrike;
import com.wimcorp.magic.behaviour.attack.FirstStrike;
import com.wimcorp.magic.behaviour.attack.LifeLink;
import com.wimcorp.magic.behaviour.attack.Trample;
import com.wimcorp.magic.behaviour.counter.Counter;
import com.wimcorp.magic.behaviour.counter.CardCountCounter;
import com.wimcorp.magic.input.BehaviorInput;

@Entity
public abstract class Behaviour {

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private Long id;
	
	@Column(columnDefinition = "text")
	private String description;

	public static Set<Behaviour> getBehavior(Set<String> behaviors) {
		Set<Behaviour> result = new HashSet<>();
		for (String behavior : behaviors) {
			result.add(getBehavior(BehaviorInput.valueOf(behavior)));
		}
		return result;
	}

	public static Behaviour getBehavior(BehaviorInput behavior) {
		switch (behavior) {
		case DEATH_TOUCH:
			return DeathTouch.instance();
		case DEFAULT_ATTACK:
			return DefaultAttack.instance();
		case DEFENDER:
			return Defender.instance();
		case DOES_NOT_UN_TAP_NEXT_TURN:
			return DoesNotUnTapNextTurn.instance();
		case DOES_NOT_UN_TAP_ON_UPKEEP:
			return DoesNotUnTapOnUpkeep.instance();
		case DOUBLE_STRIKE:
			return DoubleStrike.instance();
		case FIRST_STRIKE:
			return FirstStrike.instance();
		case FLYING:
			return Flying.instance();
		case HASTE:
			return Haste.instance();
		case HEXPROOF:
			return Hexproof.instance();
		case INTIMIDATE:
			return Intimidate.instance();
		case ISLANDWALK:
			return Islandwalk.instance();
		case LIFE_LINK:
			return LifeLink.instance();
		case MORBID:
			return Morbid.instance();
		case REACH:
			return Reach.instance();
		case SUMMONING_SICKENSS:
			return SummoningSickness.instance();
		case TAPPED:
			return Tapped.instance();
		case TRAMPLE:
			return Trample.instance();
		case UNBLOCKABLE:
			return Unblockable.instance();
		}
		return null;

	}

	@Override
	public String toString() {
		return description;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	
	@Override
	public int hashCode() {
		return getClass().getName().hashCode();
	}
	

}
